#include <iostream>
#include <unistd.h>
#include <cstdlib>
#include <signal.h>

using namespace std;

void MyHandler(int sigNo)
{
    // if(sigNo == 2) {
    //     cout << "Signal 2 two has been captured" << endl;
    //     exit(2);
    // }
    cout << "Signal has been captured" << endl;
}

int main()
{
    // 捕捉该信号，使用SIGINT或者2都可以
    signal(SIGABRT, MyHandler);
    int cnt = 5;
    while(cnt) {
        cout << "I am a process, pid: " << getpid() << endl;
        sleep(1);
    }
    abort();
    raise(SIGINT);
    return 0;
}
 